package com.ruoyi.web.controller.common;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.ApplicationInfo;
import com.ruoyi.market.service.IApplicationInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.ApplicationInfoWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 包信息管理Controller
 * 
 * @author ruoyi
 * @date 2022-11-14
 */
@Controller
@RequestMapping("/common/appInfo")
public class ApplicationInfoController extends BaseController
{
    private String prefix = "common/appInfo";

    @Autowired
    private IApplicationInfoService applicationInfoService;

    @RequiresPermissions("common:appInfo:view")
    @GetMapping()
    public String appInfo()
    {
        return prefix + "/appInfo";
    }

    /**
     * 查询包信息管理列表
     */
    @RequiresPermissions("common:appInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ApplicationInfo applicationInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = applicationInfoService.selectApplicationInfoListMap(applicationInfo);
        mapList = new ApplicationInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /*********************  应用渠道信息 ******************************/
    @GetMapping("/channelInfoView/{appType}")
    public String channelInfoView(@PathVariable("appType") String appType, ModelMap mmap)
    {
        mmap.put("appType", appType);
        return prefix + "/channelInfoView";
    }

    /**
     * 查询包信息管理列表
     */
    @PostMapping("/channelInfoList")
    @ResponseBody
    public TableDataInfo channelInfoList(@RequestParam("appType") String appType)
    {
        startPage();
        List<Map<String, Object>> mapList = applicationInfoService.selectAppChannelInfoMap(appType);
        mapList = new ApplicationInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }
    /*********************  应用渠道信息 ******************************/

    /**
     * 导出包信息管理列表
     */
    @RequiresPermissions("common:appInfo:export")
    @Log(title = "包信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ApplicationInfo applicationInfo)
    {
        List<ApplicationInfo> list = applicationInfoService.selectApplicationInfoList(applicationInfo);
        ExcelUtil<ApplicationInfo> util = new ExcelUtil<ApplicationInfo>(ApplicationInfo.class);
        return util.exportExcel(list, "包信息管理数据");
    }

    /**
     * 新增包信息管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存包信息管理
     */
    @RequiresPermissions("common:appInfo:add")
    @Log(title = "包信息管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ApplicationInfo applicationInfo)
    {
        return toAjax(applicationInfoService.insertApplicationInfo(applicationInfo));
    }

    /**
     * 修改包信息管理
     */
    @RequiresPermissions("common:appInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ApplicationInfo applicationInfo = applicationInfoService.selectApplicationInfoById(id);
        mmap.put("applicationInfo", applicationInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存包信息管理
     */
    @RequiresPermissions("common:appInfo:edit")
    @Log(title = "包信息管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ApplicationInfo applicationInfo)
    {
        return toAjax(applicationInfoService.updateApplicationInfo(applicationInfo));
    }

    /**
     * 删除包信息管理
     */
    @RequiresPermissions("common:appInfo:remove")
    @Log(title = "包信息管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(applicationInfoService.deleteApplicationInfoByIds(ids));
    }
}
